import pandas as pd
import numpy as np
tradedays=(pd.DataFrame([['20211231',16.86,16.48,-0.34],['20211230',16.76,16.82,0.07],
                         ['20211229',17.16,16.75,-0.42],['20211228',17.22,17.17,-0.05],
                         ['20211227',17.33,17.22,-0.09]],
                        columns=['trade_date','open','close','change'])
           .assign(exchange=pd.Series(dtype='float64')))
tradedays.index=['a','b','c','d','e']
tradedays=tradedays.reindex(['a','b','c','d','e','f'],fill_value=0)
tradedays=tradedays.set_index('trade_date')
tradedays=tradedays.rename(index={0:'20211226'})
tradedays.loc[['20211231','20211229','20211227'],'exchange']=np.random.uniform(1,3,size=3).round(2)
tradedays.loc['20211226','exchange']=np.nan
tradedays['exchange']=tradedays['exchange'].ffill()
tradedays['ex_dividend_date']=np.random.choice([1,0],size=len(tradedays))
prices=tradedays[['open','close','ex_dividend_date']]
tradedays.loc['20211223']={'open':17.4,'close':17.32,'change':-0.08,'exchange':round(np.random.uniform(1,3),2),
                           'ex_dividend_date':np.random.choice([0,1])}

data={'open':17,'close':17,
'exchange':round(np.random.uniform(1,3),2),'ex_dividend_date':np.random.choice([0,1])}

# 创建一个新的行数据
row = pd.DataFrame(data, index=['20211224'])
# 将新的行数据插入到倒数第2行
tradedays= pd.concat([tradedays.iloc[:-1],row, tradedays.iloc[-1:]])
print(tradedays)